+ 'current_month': self.current_month,
+ 'last_month': self.last_month,
+ }
@@ -0,0 +1,6 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+from __future__ import unicode_literals |
|
| 3 |
+ |
|
| 4 |
+from django.test import TestCase |
|
| 5 |
+ |
|
| 6 |
+# Create your tests here. |
@@ -0,0 +1,82 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from __future__ import division |
|
| 4 |
+ |
|
| 5 |
+from django.conf import settings |
|
| 6 |
+from django_logit import logit |
|
| 7 |
+from django_response import response |
|
| 8 |
+from TimeConvert import TimeConvert as tc |
|
| 9 |
+ |
|
| 10 |
+from mch.models import DistributorInfo |
|
| 11 |
+from sales.models import SalesResponsibilityInfo, SalesResponsibilityInfoModelsSaleStatisticInfo, SuperSalesResponsibilityInfoModelsSaleStatisticInfo |
|
| 12 |
+from utils.error.errno_utils import SalesResponsibilityStatusCode |
|
| 13 |
+ |
|
| 14 |
+ |
|
| 15 |
+@logit |
|
| 16 |
+def sr_submit_api(request): |
|
| 17 |
+ brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
|
|
| 18 |
+ user_id = request.POST.get('user_id', '')
|
|
| 19 |
+ unionid = request.POST.get('unionid', '')
|
|
| 20 |
+ openid = request.POST.get('openid', '')
|
|
| 21 |
+ phone = request.POST.get('phone', '')
|
|
| 22 |
+ |
|
| 23 |
+ if SalesResponsibilityInfo.objects.filter(brand_id=brand_id, phone=phone).exclude(user_id=user_id).exists(): |
|
| 24 |
+ return response(SalesResponsibilityStatusCode.SR_PHONE_ALREADY_EXISTS) |
|
| 25 |
+ |
|
| 26 |
+ SalesResponsibilityInfo.objects.update_or_create(brand_id=brand_id, user_id=user_id, defaults={
|
|
| 27 |
+ 'name': request.POST.get('name', ''),
|
|
| 28 |
+ 'phone': request.POST.get('phone', ''),
|
|
| 29 |
+ 'unionid': unionid, |
|
| 30 |
+ 'openid': openid, |
|
| 31 |
+ 'user_status': SalesResponsibilityInfo.UNVERIFIED, |
|
| 32 |
+ 'status': True, |
|
| 33 |
+ }) |
|
| 34 |
+ |
|
| 35 |
+ return response(200, 'Submit Success', u'提交成功', {})
|
|
| 36 |
+ |
|
| 37 |
+ |
|
| 38 |
+@logit |
|
| 39 |
+def sr_distributor_list(request): |
|
| 40 |
+ brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
|
|
| 41 |
+ user_id = request.POST.get('user_id', '')
|
|
| 42 |
+ sr_id = request.POST.get('sr_id', '')
|
|
| 43 |
+ |
|
| 44 |
+ # if not sr_id: |
|
| 45 |
+ # try: |
|
| 46 |
+ # sr = SalesResponsibilityInfo.objects.get(brand_id=brand_id, user_id=user_id) |
|
| 47 |
+ # except SalesResponsibilityInfo.DoesNotExist: |
|
| 48 |
+ # return response(SalesResponsibilityStatusCode.SR_NOT_FOUND) |
|
| 49 |
+ # sr_id = sr.sr_id |
|
| 50 |
+ |
|
| 51 |
+ distributors = DistributorInfo.objects.filter(brand_id=brand_id, sr_id=sr_id, status=True) |
|
| 52 |
+ distributors = [d.admindata for d in distributors] |
|
| 53 |
+ |
|
| 54 |
+ return response(data={
|
|
| 55 |
+ 'distributors': distributors, |
|
| 56 |
+ }) |
|
| 57 |
+ |
|
| 58 |
+ |
|
| 59 |
+@logit |
|
| 60 |
+def sr_distributor_tj(request): |
|
| 61 |
+ brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
|
|
| 62 |
+ distributor_id = request.POST.get('distributor_id', '')
|
|
| 63 |
+ |
|
| 64 |
+ sales = SalesResponsibilityInfoModelsSaleStatisticInfo.objects.filter(brand_id=brand_id, distributor_id=distributor_id, ymd=tc.local_string(format='%Y%m%d'), status=True).order_by('-is_important')
|
|
| 65 |
+ sales = [sale.data for sale in sales] |
|
| 66 |
+ |
|
| 67 |
+ return response(data={
|
|
| 68 |
+ 'sales': sales, |
|
| 69 |
+ }) |
|
| 70 |
+ |
|
| 71 |
+ |
|
| 72 |
+@logit |
|
| 73 |
+def supersr_sr_tj(request): |
|
| 74 |
+ brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
|
|
| 75 |
+ sr_id = request.POST.get('sr_id', '')
|
|
| 76 |
+ |
|
| 77 |
+ sales = SuperSalesResponsibilityInfoModelsSaleStatisticInfo.objects.filter(brand_id=brand_id, sr_id=sr_id, ymd=tc.local_string(format='%Y%m%d'), status=True).order_by('-is_important')
|
|
| 78 |
+ sales = [sale.data for sale in sales] |
|
| 79 |
+ |
|
| 80 |
+ return response(data={
|
|
| 81 |
+ 'sales': sales, |
|
| 82 |
+ }) |
@@ -16,6 +16,13 @@ class SaleclerkStatusCode(BaseStatusCode): |
||
| 16 | 16 |
DUPLICATE_SUBMIT = StatusCodeField(500199, 'Duplicate Submit', description=u'重复提交') |
| 17 | 17 |
|
| 18 | 18 |
|
| 19 |
+class SalesResponsibilityStatusCode(BaseStatusCode): |
|
| 20 |
+ """ 销售担当相关错误码 5002xx """ |
|
| 21 |
+ SR_NOT_FOUND = StatusCodeField(500201, 'SR Not Found', description=u'销售担当不存在') |
|
| 22 |
+ # 手机号 |
|
| 23 |
+ SR_PHONE_ALREADY_EXISTS = StatusCodeField(500205, 'SR Phone Already Exists', description=u'手机号已经存在') |
|
| 24 |
+ |
|
| 25 |
+ |
|
| 19 | 26 |
class ProductBrandStatusCode(BaseStatusCode): |
| 20 | 27 |
""" 品牌相关错误码 5010xx """ |
| 21 | 28 |
BRAND_NOT_FOUND = StatusCodeField(501001, 'Brand Not Found', description=u'品牌不存在') |